Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cliclopts

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cliclopts

Command line options helper and usage printer

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by35.37%
Maintainers
2
Weekly downloads
 
Created
Source

cliclopts

NPM

cliclopts

Command line options helper and usage printer, works well with minimist, inspired by nomnom

js-standard-style

usage

Define the allowed options in an array and pass it to 'cliclopts'

var cliclopts = require('cliclopts')

var options = [
  {
    name: 'verbose',
    abbr: 'v',
    alias: ['loud'],
    boolean: true,
    help: 'be verbose'
  },
  {
    name: 'path',
    abbr: 'p',
    default: './dat.json',
    help: 'path to file'
  }
]

var cliOpts = cliclopts(options)

cliclopts(options)

options is an array of objects with the following possible keys:

  • name primary name of option
  • abbr one character alias of the option
  • alias other options treated as alias
  • boolean if true the option is seen as a boolean flag
  • help usage string for the option
  • default default value of the option

cliOpts.usage()

Returns the usage information as string:

--verbose, -v         be verbose
--path, -p            path to file (default: "dat.json")

cliOpts.print()

Prints the usage information.

cliOpts.boolean()

Returns Array of all command names that are specified as boolean.

cliOpts.alias()

Returns Object with command names as keys and alias list as value (including abbr)

cliOpts.default()

Returns Object with command names as keys and default values as values.

cliOpts.options()

Returns

{
  alias: cliOpts.alias(),
  boolean: cliOpts.boolean(),
  default: cliOpts.default()
}

Example usage with minimist

var allowedOptions = [
  {
    name: 'verbose',
    abbr: 'v',
    alias: ['cry-at-me'],
    boolean: true,
    help: 'be verbose'
  },
  {
    name: 'path',
    abbr: 'p',
    help: 'path to the file'
  },
  {
    name: 'help',
    abbr: 'h',
    help: 'show help',
    boolean: true
  }
]

var cliOpts = require('cliclopts')(allowedOptions)

var argv = require('minimist')(process.argv.slice(2), cliOpts.options())

if (argv.help) {
  console.log('Usage: command [options]')
  cliOpts.print()
  process.exit()
}

yourprogram(argv)

Keywords

FAQs

Package last updated on 07 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc